﻿#region Imports
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using BulkRenamer.App.Properties;
using BulkRenamer.App.Views;
using CommonUtilities.Util;
#endregion

namespace BulkRenamer.App.Main
{
    static class Program
    {
        #region Properties
        private static Settings bulkRenamerSettings = new Settings();
        internal static Settings BulkRenamerSettings
        {
            get { return bulkRenamerSettings; }
            private set { bulkRenamerSettings = value; }
        }

        /// <summary>
        /// Defines if code is currently being used for debugging
        /// </summary>
        public static bool IsDebug
        {
            get { return Debugger.IsAttached ? true : (bool)BulkRenamerSettings["DebugMode"]; }
            //get { return Debugger.IsAttached; }
        }
        #endregion

        #region Methods
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetForegroundWindow(IntPtr hWnd);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            SimpleDelegate pre = () =>
            {
                if (!IsDebug) RegistryOperator.CheckRunRegistry(RestartApp);
                MessageBox.Show("Debugger.IsAttached :: " + Debugger.IsAttached.ToString(), "Debugger");
            };

            AppInstance.ValidateAppInstances<frmBulkRenamer>(pre, null, IsDebug);
        }

        private static void RestartApp()
        {
            Application.Restart();
        }
        #endregion
    }
}
